Geospatial Analysis and Python

Victoria Jent and Andrew Fair

Pop Health Analysts Group, 5/27/2021

Overview of Concepts

Overview of GUI Tools

Overview of Coding Options

Why consider Python (or R)?

Demonstration of techniques

Geocoding Demo

Read in NYCHA address data

We have one null value for ZIP code - we'll want to get rid of that

Let's concatenate Address and ZIP code together

Don't leave your personal token in your production script!
You can create a free account with Geocodio here to get a token: https://dash.geocod.io/register

Geocodio allows 2,500 free lookups per day - we'll take a sample of 25 so we don't blow it up

Now we'll call the geocoding API
https://www.geocod.io/docs/?python#single-address

Draw out latitude & longitude into their own fields

Mapping with Plotly Demo

Read in ZCTA COVID data and get it into proper shape (sorry, this isn't a pandas demo!)
Source: https://github.com/nychealth/coronavirus-data/blob/master/trends/percentpositive-by-modzcta.csv

Read in ZCTA geojson file
Source: https://github.com/nychealth/coronavirus-data/tree/master/Geography-resources

We'll use mapbox for some extra formatting control - it's not strictly necessary
Otherwise, you might get some display wonkiness if you leave the default map style - I think it's a known bug, and will probably get fixed sooner or later
You can create a free Mapbox account here for a token: https://account.mapbox.com/auth/signup/

Set plot dimensions

Set up choropleth map object
You get lots of parameters to play with

Set up scatterplot object to overlay on top of choropleth

Set layout parameters

Now, plot it!